import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
/*
* 类似 转派到个人弹窗
*
*/

class PublicAssignedToPersonToast extends Dialog {
  Function onCloseEvent;
  Function onPositivePressEvent;
  Function onFindPressEvent;
  Function findEvent;
  String title;
  String agreetText;
  String cancelText;
  String custname;
  String custNum;
  PublicAssignedToPersonToast({
    this.agreetText,
    this.cancelText,
    this.title,
    this.findEvent,
    this.onPositivePressEvent,
    this.custname,
    this.custNum,
    @required this.onCloseEvent,
  });
  TextEditingController _contentController = new TextEditingController();
  FocusNode _contentFocusNode = FocusNode();
  Widget MainComponent(){
    return Stack(
      children: [
        Opacity(
          opacity: 0.46,
          child:Container(
            color: Color(0xff101010),
            width: ScreenUtil.screenWidth,
            height: ScreenUtil.screenHeight,
          ) ,
        ),
        Positioned(
            top: ScreenUtil().setWidth(250),
            left: ScreenUtil().setWidth(503),
            child: CenterWidget()
        ),
      ],
    );
  }
  //中间视图背景
  Widget CenterBG(){
    return Container(
      decoration: ShapeDecoration(
        color: Color(0xffffffff),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(11.2),
          ),
        ),
      ),
      width:ScreenUtil().setWidth(983) ,
      height: ScreenUtil().setWidth(739.2),
    );
  }
  //中间视图
  Widget CenterWidget(){
    return Stack(
        children: <Widget>[
          CenterBG(),
          Positioned(
            left: ScreenUtil().setWidth(0),
            top: ScreenUtil().setWidth(0),
            child: Container(
              width: ScreenUtil().setWidth(983),
              height: ScreenUtil().setWidth(77.6),
              decoration: ShapeDecoration(
                color: Color(0xffF6F5F7),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(11.2),
                    topRight: Radius.circular(11.2),
                  ),
                ),
              ),
              child:Row(
                children: [
                  SizedBox(width:ScreenUtil().setWidth(44),),
                  Text(title, style: TextStyle(color: Color(0xff000000), fontFamily: 'PingFangSC-Medium',fontSize:ScreenUtil().setSp(26)),textAlign: TextAlign.center,),
                  SizedBox(width:ScreenUtil().setWidth(764),),
                  InkWell(
                    onTap: onCloseEvent,
                    child:Image.asset('sources/x.png',width: ScreenUtil().setWidth(13.4),height: ScreenUtil().setWidth(14),),
                  ),
                ],
              ),
            ),
          ),
          Positioned(
            child: Container(
              width: ScreenUtil().setWidth(983),
              height: ScreenUtil().setWidth(122.4),
              child:Column(
                children: [
                  SizedBox(height: ScreenUtil().setWidth(30.4),),
                  Row(
                    children: [
                      SizedBox(width:ScreenUtil().setWidth(42)),
                      inputWidget(),
                      SizedBox(width: ScreenUtil().setWidth(24),),
                      inputWidget(),
                      SizedBox(width: ScreenUtil().setWidth(128),),
                      InkWell(
                        onTap: this.findEvent(custname??"",custNum??""),
                        child: Container(
                           decoration: new BoxDecoration(
                           color: Colors.white,
                           borderRadius: BorderRadius.all(Radius.circular(30.0)),
                           border: new Border.all(width: ScreenUtil().setWidth(1.88), color: Color(0xffF22A02),),
                           boxShadow: [
                                BoxShadow(
                                  color: Color(0xffFA7777),
                                  offset: Offset(0, 2.0), //阴影y轴偏移量
                                  blurRadius: 10.0, //阴影模糊程度
                                  spreadRadius: 0 //阴影扩散程度
                                )
                           ],
                          ),
                          width: ScreenUtil().setWidth(164.7),
                          height: ScreenUtil().setWidth(60),
                          child: Center(
                               child:Text("查询",style: TextStyle(fontFamily:"PingFangSC-Regular",fontSize: ScreenUtil().setSp(24),color: Color(0xffF22A02)),textAlign: TextAlign.center,)) ,
                          ),
                        ),
                    ],
                  )

                ],
              ),
            ),
            top: ScreenUtil().setWidth(77.6),
            left: ScreenUtil().setWidth(0),
          ),
          Positioned(
              left: 0,
              top: ScreenUtil().setWidth(202),
              child: listViewWidget(),
          ),
          Positioned(
            child: InkWell(
                onTap:this.onPositivePressEvent,
                child: Container(
                  width: ScreenUtil().setWidth(222),
                  height: ScreenUtil().setWidth(60),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(30),
                    color:Color(0xffF22A02),
                    boxShadow: [
                      BoxShadow(
                          color: Color(0xffA1120B),
                          offset: Offset(4, 0.9), //阴影y轴偏移量
                          blurRadius: 12.0, //阴影模糊程度
                          spreadRadius: 0 //阴影扩散程度
                      )
                    ],
                  ),
                  child: new Center(
                    child:new Text(agreetText??"转派",style: TextStyle(fontSize: ScreenUtil().setSp(24),color: Color(0xffFFFFFF)),textAlign: TextAlign.center,),
                  ),
                )
            ),
            left: ScreenUtil().setWidth(396),
            top: ScreenUtil().setWidth(646),
          ),
        ]
    );
  }

  Widget inputWidget(){
    return Container(
      height:ScreenUtil().setWidth(60),
      width: ScreenUtil().setWidth(299),
      decoration: new BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(30.0)),
        border: new Border.all(width: 1, color: Color(0xffC8C8C8),),
        boxShadow: [
          BoxShadow(
              color: Color(0xffC8C8C8),
              offset: Offset(0, 2.0), //阴影y轴偏移量
              blurRadius: 11.0, //阴影模糊程度
              spreadRadius: 0 //阴影扩散程度
          )
        ],
      ),
      child: TextField(
        focusNode: _contentFocusNode,
        controller: _contentController,
        maxLines: 1, //不限制行数
        keyboardType: TextInputType.multiline,
        decoration: InputDecoration(
          fillColor: Colors.white,
          filled: true,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(30),
          borderSide: BorderSide.none),
          hintText: '请输入客户经理姓名',
        ),
        style: TextStyle(fontFamily: "PingFangSC-Regular", color: Colors.black,fontSize: ScreenUtil().setSp(24),),textAlign: TextAlign.left,
        //文本内容改变时回调
        onChanged: (text) {
          print('文本内容改变时回调 $text');
          // chooseCallback(text);
          _contentController.text = text;
          _contentController.selection = TextSelection.fromPosition(
              TextPosition(offset: _contentController.text.length));
        },
        //内容提交时回调
        onSubmitted: (text) {
          print('内容提交时回调 $text');
        },
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1600, height: 900, allowFontScaling: true);
    return new Material(
        type: MaterialType.transparency,
        child: new Center(
          child: CenterWidget(),
        )
    );
  }
}


class listViewWidget extends StatefulWidget {
  @override
  _listViewWidgetState createState() => _listViewWidgetState();
}

class _listViewWidgetState extends State<listViewWidget> {

  int selectedIndex = -1;
  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(983),
      height: ScreenUtil().setWidth(404),
      child:ListView.separated(
          itemBuilder: (BuildContext context,int index){
            return InkWell(
              onTap: (){
                   setState(() {
                     selectedIndex = index;
                   });
              },
              child: ListTile(
                  title:Row(
                    children: [
                      SizedBox(width: ScreenUtil().setWidth(52),),
                      Container(
                        child: Center(
                            child:Text("张三  1000101",style: TextStyle(fontFamily: "PingFangSC-Regular;",fontSize:ScreenUtil().setSp(24),color: index ==selectedIndex?Color(0xffF22A02):Color(0xff333333) ),)
                        ),
                        height: ScreenUtil().setWidth(98),
                      )
                    ],
                  )
              ),
            );
          },
          separatorBuilder: (BuildContext context,int index){
            return  Container(color:Color(0xffE4E3E3),width: ScreenUtil().setWidth(983),height: ScreenUtil().setWidth(1),);
          },
          itemCount: 100
      ),
    );
  }
}

